package com.xing.controller;

import com.xing.DTO.UserRoleSaveDTO;
import com.xing.Utils.Result;
import com.xing.entity.SysRoleEntity;
import com.xing.service.SysUserRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "用户角色关联服务")
@RestController
@RequestMapping(value = "userRoleRelation")
public class SysUserRoleController {

    @Autowired
    private SysUserRoleService userRoleService;


    @Operation(summary = "根据id获取角色id")
    @GetMapping(value = "getRoleIdByUserId")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result getRoleIdByUserId(@RequestParam Long userId) {
        List<Long> roleIdList = userRoleService.getRoleIdByUserId(userId);
        return new Result().ok(roleIdList);
    }


    @Operation(summary = "授予用户角色列表")
    @PostMapping(value = "saveUserRole")
    @PreAuthorize("hasAnyAuthority('admin')")
    public Result saveUserRoleRelation(@RequestBody UserRoleSaveDTO userRoleSaveDTO) {
        return userRoleService.saveUserRoleRelation(userRoleSaveDTO);
    }

}
